(function(){var e=window.BX;e.namespace("BX.UI");if(!!e.UI.Selector){return}e.UI.Selector=function(t){this.statuses={searchWaiterEnabled:false};this.manager=e.UI.SelectorManager;this.id=e.type.isNotEmptyString(t.id)?t.id:null;this.fieldName=e.type.isNotEmptyString(t.fieldName)?t.fieldName:null;this.tabs={list:{},selected:null};this.dialogGroups={};this.entities=e.type.isNotEmptyObject(t.entities)?t.entities:{};this.networkItems={};this.sortData={};this.itemsSelected=e.type.isNotEmptyObject(t.itemsSelected)?t.itemsSelected:{};this.itemsUndeletable=e.type.isNotEmptyObject(t.itemsUndeletable)?t.itemsUndeletable:[];this.options=e.type.isNotEmptyObject(t.options)?t.options:{};this.bindOptions=e.type.isNotEmptyObject(t.bindOptions)?t.bindOptions:{};this.bindOptions.forceBindPosition=true;this.popups={container:null,main:null,search:null,inviteEmailUser:null};this.nodes={input:e.type.isDomNode(t.input)?t.input:null,inputBox:e.type.isDomNode(t.inputBox)?t.inputBox:null,inputItemsContainer:e.type.isDomNode(t.inputItemsContainer)?t.inputItemsContainer:null,tag:e.type.isDomNode(t.tag)?t.tag:null,containerContentsContainer:null,searchContentsContainer:null,contentWaiter:null,searchWaiter:null};this.cursors={};this.result={search:[]};this.resultChanged={};this.tmpSearchResult={client:[],ajax:[]};this.callback=e.type.isNotEmptyObject(t.callback)?t.callback:{};this.callbackBefore=e.type.isNotEmptyObject(t.callbackBefore)?t.callbackBefore:{};this.searchXhr=null;this.searchRequestId=null;this.timeouts={search:null};this.dialogNodes={tabsContainer:null,contentsContainer:null};this.treeItemLoaded={};this.clientDBSearchResult={users:{}};this.ajaxSearchResult={users:{}};this.containerSearchResult={};this.searchInstance=null;this.navigationInstance=null;this.renderInstance=null;this.postponeSearch=false;this.closeByEmptySearchResult=false;var s=this.getOption("search");if(e.type.isNotEmptyString(s.useClientDatabase)&&s.useClientDatabase=="Y"){e.onCustomEvent("BX.UI.SelectorManager:initClientDatabase",[])}};e.UI.Selector.create=function(t){var s=new e.UI.Selector(t);e.UI.SelectorManager.instances[t.id]=s;e.onCustomEvent("BX.UI.SelectorManager:onCreate",[t.id]);return s};e.UI.Selector.prototype.getSearchInstance=function(){if(this.searchInstance===null){this.searchInstance=e.UI.Selector.Search.create({selectorInstance:this})}return this.searchInstance};e.UI.Selector.prototype.getNavigationInstance=function(){if(this.navigationInstance===null){this.navigationInstance=e.UI.Selector.Navigation.create({selectorInstance:this})}return this.navigationInstance};e.UI.Selector.prototype.getRenderInstance=function(){if(this.renderInstance===null){this.renderInstance=e.UI.Selector.Render.create({selectorInstance:this})}return this.renderInstance};e.UI.Selector.prototype.getPopupBind=function(){return e.type.isNotEmptyObject(this.bindOptions.position)?this.bindOptions.position:this.bindOptions.node};e.UI.Selector.prototype.getPopupZIndex=function(){return e.type.isNotEmptyObject(this.bindOptions)&&typeof this.bindOptions.zIndex!="undefined"?this.bindOptions.zIndex:1200};e.UI.Selector.prototype.openDialog=function(){var t=this.getPopupBind();if(e.type.isDomNode(t)&&!document.body.contains(t)){return}var s=false;var i=null;if(typeof this.callbackBefore.openDialog=="function"){if(e.type.isNotEmptyObject(this.callbackBefore.context)){i=this.callbackBefore.openDialog.bind(this.callbackBefore.context)();s=i&&(Object.prototype.toString.call(i)==="[object Promise]"||i.toString()==="[object BX.Promise]")}}if(!s){i=Promise.resolve()}i.then(this.openDialogPromiseFulfilled.bind(this),this.openDialogPromiseRejected.bind(this))};e.UI.Selector.prototype.openDialogPromiseFulfilled=function(t){var s=this.getPopupBind();if(e.type.isDomNode(s)&&!document.body.contains(s)){return}if(this.getOption("useContainer")=="Y"){if(!this.openContainer()){return false}e.cleanNode(this.nodes.containerContentsContainer);this.nodes.containerContentsContainer.appendChild(this.getDialogContent());var i=null;for(var n in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(n)){i=this.manager.convertEntityType(this.itemsSelected[n]);if(this.callback.select){this.callback.select({item:this.entities[i].items[n],entityType:i,selectorId:this.id,state:"init"})}}}this.popups.container.setAngle({});this.popups.container.setBindElement(s);this.popups.container.show()}else{this.popups.main=new e.PopupWindow({id:"bx-selector-dialog-"+this.id,bindElement:s,autoHide:this.getOption("popupAutoHide")!="N",zIndex:this.getPopupZIndex(),className:this.getRenderInstance().class.popup,offsetLeft:this.bindOptions.offsetLeft,offsetTop:this.bindOptions.offsetTop,bindOptions:this.bindOptions,cacheable:false,closeByEsc:true,closeIcon:this.getOption("showCloseIcon")=="Y"?{top:"12px",right:"15px"}:false,lightShadow:true,events:{onPopupShow:function(){if(this.manager.statuses.allowSendEvent&&this.callback.openDialog){this.callback.openDialog({selectorId:this.id})}if(this.popups.inviteEmailUser&&this.popups.inviteEmailUser.isShown()){this.popups.inviteEmailUser.close()}}.bind(this),onPopupDestroy:function(){this.popups.main=null;if(this.manager.statuses.allowSendEvent&&this.callback.closeDialog){this.callback.closeDialog({selectorId:this.id})}}.bind(this)},content:this.getDialogContent()});this.popups.main.setAngle({});this.popups.main.show()}if(this.getOption("enableLast")!="N"){this.tabs.selected="last"}if(this.getOption("enableLast")=="N"&&this.getOption("enableSonetgroups")!="Y"&&this.getOption("enableDepartments")=="Y"){this.switchTab({code:"departments"});if(this.getOption("useContainer")=="Y"){this.popups.container.adjustPosition()}else{this.popups.main.adjustPosition()}}this.getNavigationInstance().hoverFirstItem({tab:this.tabs.selected})};e.UI.Selector.prototype.openDialogPromiseRejected=function(e){this.callback.closeDialog({selectorId:this.id})};e.UI.Selector.prototype.openContainer=function(){if(this.popups.container){this.popups.container.destroy()}this.popups.container=new e.PopupWindow({id:"bx-selector-dialog-"+this.id+"-container",bindElement:this.getPopupBind(),autoHide:this.getOption("popupAutoHide")!="N",zIndex:this.getPopupZIndex(),className:this.getRenderInstance().class.popup,offsetLeft:this.bindOptions.offsetLeft,offsetTop:this.bindOptions.offsetTop,bindOptions:this.bindOptions,cacheable:false,closeByEsc:true,closeIcon:this.getOption("showCloseIcon")=="Y"?{top:0,right:0}:false,lightShadow:true,events:{onPopupShow:function(){if(this.manager.statuses.allowSendEvent&&this.callback.openDialog){this.callback.openDialog({selectorId:this.id})}if(this.popups.inviteEmailUser&&this.popups.inviteEmailUser.isShown()){this.popups.inviteEmailUser.close()}}.bind(this),onPopupDestroy:function(){this.popups.container=null;if(this.manager.statuses.allowSendEvent){if(this.callback.closeDialog){this.callback.closeDialog({selectorId:this.id})}if(this.callback.closeSearch){this.callback.closeSearch({selectorId:this.id})}}}.bind(this)},content:this.getContainerContent()});return true};e.UI.Selector.prototype.openSearch=function(t){this.manager.statuses.allowSendEvent=false;if(this.popups.main!=null){this.popups.main.close()}this.manager.statuses.allowSendEvent=true;if(this.popups.search!=null){this.popups.search.close();return false}if(this.getOption("useContainer")=="Y"){this.containerSearchResult=t.itemsList;if(this.nodes.searchContent){e.cleanNode(this.nodes.searchContent);var s=this.buildContentCollection({type:"search",items:t.itemsList});for(i=0;i<s.length;i++){this.nodes.searchContent.appendChild(s[i])}}else{e.cleanNode(this.nodes.searchContent);e(this.nodes.searchContent).appendChild(this.getSearchContent({itemsList:t.itemsList}))}this.switchTab({code:"search"});this.popups.container.setAngle({})}else{this.popups.search=new e.PopupWindow({id:"bx-selector-dialog-"+this.id+"-search",bindElement:this.getPopupBind(),autoHide:true,zIndex:this.getPopupZIndex(),className:this.getRenderInstance().class.popup,offsetLeft:this.bindOptions.offsetLeft,offsetTop:this.bindOptions.offsetTop,bindOptions:this.bindOptions,cacheable:false,closeByEsc:true,closeIcon:false,lightShadow:true,events:{onPopupShow:function(){if(this.manager.statuses.allowSendEvent&&this.callback.openSearch){this.callback.openSearch({selectorId:this.id})}if(this.popups.inviteEmailUser&&this.popups.inviteEmailUser.isShown()){this.popups.inviteEmailUser.close()}}.bind(this),onPopupDestroy:function(){this.popups.search=null;this.getSearchInstance().abortSearchRequest();if(this.manager.statuses.allowSendEvent&&this.callback.closeSearch){this.callback.closeSearch({selectorId:this.id})}}.bind(this)},content:this.getSearchContent({itemsList:t.itemsList})});this.popups.search.setAngle({});this.popups.search.show()}this.getNavigationInstance().hoverFirstItem({tab:"search"})};e.UI.Selector.prototype.getDialogContent=function(){this.dialogNodes.tabsContainer=e.create("DIV",{props:{className:this.getRenderInstance().class.tabsContainer}});var t=null,s=0,i=[];for(var n in this.tabs.list){if(this.tabs.list.hasOwnProperty(n)){t=this.tabs.list[n];i.push({code:n,value:typeof t["sort"]!="undefined"&&parseInt(t["sort"])>0?parseInt(t["sort"]):100})}}if(this.getOption("useContainer")=="Y"&&!e.type.isNotEmptyObject(this.tabs.list["search"])){this.tabs.list["search"]={name:e.message("MAIN_UI_SELECTOR_SEARCH_TAB_TITLE")};i.push({code:"search",value:1e4})}i.sort((function(e,t){if(e.value<t.value){return-1}if(e.value>t.value){return 1}return 0}));var a=[];var o=null;for(var r=0;r<i.length;r++){n=i[r].code;t=this.tabs.list[n];if(s===0){this.tabs.selected=n}o=e.create("A",{attrs:{hidefocus:"true","data-code":n},props:{className:this.getRenderInstance().class.tab+" "+this.getRenderInstance().class.tabLast+" "+(s==0?this.getRenderInstance().class.tabSelected:"")},events:{click:function(e){this.switchTab({code:e.target.getAttribute("data-code")});e.stopPropagation();return e.preventDefault()}.bind(this)},html:t.name});this.dialogNodes.tabsContainer.appendChild(o);a.push(this.buildContentNode({type:n}));s++}this.dialogNodes.contentsContainer=e.create("DIV",{props:{className:this.getRenderInstance().class.tabsContentContainer+" "+this.getRenderInstance().class.tabsContentContainerWindow},children:[e.create("TABLE",{props:{className:this.getRenderInstance().class.tabsContentContainerTable},children:[e.create("TR",{children:[e.create("TD",{props:{className:this.getRenderInstance().class.tabsContentContainerCell},children:a})]})]})]});var c=this.getOption("windowClass");return e.create("DIV",{style:{minWidth:"650px",paddingBottom:"8px"},props:{className:this.getRenderInstance().class.boxCommon+" "+this.getRenderInstance().class.boxContainer+" "+this.getRenderInstance().class.boxContainerVertical+" "+(c?c:this.getRenderInstance().class.boxDefault)},children:[this.dialogNodes.tabsContainer,this.dialogNodes.contentsContainer]})};e.UI.Selector.prototype.getContainerContent=function(){var t=this.getOption("windowClass"),s=null;this.nodes.containerContentsContainer=e.create("div",{props:{className:this.getRenderInstance().class.containerContent}});this.nodes.inputItemsContainer=e.create("SPAN",{attrs:{id:"bx-dest-internal-item"}});var i=e.create("DIV",{children:[e.create("DIV",{props:{className:this.getRenderInstance().class.boxCommon+" "+this.getRenderInstance().class.boxContainer+" "+this.getRenderInstance().class.boxContainerVertical+" "+(t?t:this.getRenderInstance().class.boxDefault)},style:{minWidth:"650px",paddingBottom:"8px",overflow:"hidden"},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.containerSearchBlock},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.containerSearchBlockCell},children:[this.nodes.inputItemsContainer,e.create("SPAN",{attrs:{id:"bx-dest-internal-input-box"},style:{display:"inline-block"},props:{className:this.getRenderInstance().class.containerSearchBlockInputBox},children:[this.getSearchInput()]})],events:{click:function(t){e.focus(this.nodes.input);return t.preventDefault()}.bind(this)}})]}),this.nodes.containerContentsContainer]})]});e.bind(this.nodes.input,"keydown",function(e){this.getSearchInstance().beforeSearchHandler({event:e})}.bind(this));e.bind(this.nodes.input,"keyup",function(e){this.getSearchInstance().searchHandler({event:e})}.bind(this));e.bind(this.nodes.input,"paste",function(e){this.getSearchInstance().searchHandler({event:e})}.bind(this));e.defer(e.focus)(this.nodes.input);return i};e.UI.Selector.prototype.getSearchInput=function(){this.nodes.input=e.create("INPUT",{attrs:{type:"text"},props:{className:this.getRenderInstance().class.containerSearchBlockInput}});return this.nodes.input};e.UI.Selector.prototype.getSearchContent=function(t){this.nodes.searchContentsContainer=e.create("DIV",{attrs:{},props:{className:this.getRenderInstance().class.tabsContentContainer+" "+this.getRenderInstance().class.tabsContentContainerWindow},children:[e.create("TABLE",{props:{className:this.getRenderInstance().class.tabsContentContainerTable},children:[e.create("TR",{children:[e.create("TD",{props:{className:this.getRenderInstance().class.tabsContentContainerCell},children:[this.buildContentNode({type:"search",items:t.itemsList})]})]})]})]});var s=this.getOption("windowClass");return e.create("DIV",{style:{minWidth:"650px",paddingBottom:"8px"},props:{className:this.getRenderInstance().class.boxCommon+" "+this.getRenderInstance().class.boxContainer+" "+this.getRenderInstance().class.boxContainerVertical+" "+(s?s:this.getRenderInstance().class.boxDefault)},children:[this.nodes.searchContentsContainer,this.getOption("useContainer")=="Y"?null:this.getSearchInstance().buildSearchWaiter()]})};e.UI.Selector.prototype.switchTab=function(t){var s=e.type.isNotEmptyString(t.code)?t.code:null;if(!s){return}var i=null,n=null;this.tabs.selected=s;var a=e.findChildren(this.dialogNodes.tabsContainer,{className:this.getRenderInstance().class.tab},true);if(a){for(i=0;i<a.length;i++){if(a[i].getAttribute("data-code")==s){a[i].classList.add(this.getRenderInstance().class.tabSelected)}else{a[i].classList.remove(this.getRenderInstance().class.tabSelected)}}}a=e.findChildren(this.dialogNodes.contentsContainer,{className:this.getRenderInstance().class.tabContent},true);if(a){for(i=0;i<a.length;i++){if(a[i].getAttribute("data-code")==s){e.cleanNode(a[i]);var o=this.buildContentCollection({type:s,items:s=="search"?this.containerSearchResult:null});for(n=0;n<o.length;n++){a[i].appendChild(o[n])}a[i].classList.add(this.getRenderInstance().class.tabContentSelected)}else{a[i].classList.remove(this.getRenderInstance().class.tabContentSelected)}}}this.getNavigationInstance().hoverFirstItem({tab:s});if(this.getOption("focusInputOnSwitchTab")!="N"){e.focus(this.input)}var r=this.getOption("useContainer")=="Y"?this.popups.container:this.popups.main;setTimeout(function(){r.bindOptions.forceTop=true;r.bindOptions.position=this.getPopupPosition(r);r.adjustPosition();r.bindOptions.forceTop=false}.bind(this),0)};e.UI.Selector.prototype.getPopupPosition=function(t){var s=e.pos(t.getPopupContainer(),false),i=e.pos(t.bindElement,false);return s.top<i.top?"top":"bottom"};e.UI.Selector.prototype.setOption=function(t,s,i){if(!e.type.isNotEmptyString(i)){this.options[t]=s}else{i=i.toUpperCase();if(e.type.isNotEmptyObject(this.entities[i])){if(!e.type.isNotEmptyObject(this.entities[i].options)){this.entities[i].options={}}this.entities[i].options[t]=s}}};e.UI.Selector.prototype.getOption=function(t,s){if(!e.type.isNotEmptyString(s)){return typeof this.options[t]!="undefined"?this.options[t]:null}else{s=s.toUpperCase();return e.type.isNotEmptyObject(this.entities[s])&&e.type.isNotEmptyObject(this.entities[s].options)&&e.type.isNotEmptyString(this.entities[s].options[t])?this.entities[s].options[t]:null}};e.UI.Selector.prototype.buildContentNode=function(t){var s=t.type;var i=[this.tabs.selected];if(this.getOption("useContainer")!="Y"){i.push("search")}var n=[];if(e.util.in_array(s,i)){n=this.buildContentCollection(t)}var a=e.create("DIV",{attrs:{"data-code":s},props:{className:this.getRenderInstance().class.tabContent+" "+this.getRenderInstance().class.tabContentPrefix+s+" "+(e.util.in_array(s,[this.tabs.selected,"search"])?this.getRenderInstance().class.tabContentSelected:"")},children:n});if(s=="search"){this.nodes.searchContent=a}return a};e.UI.Selector.prototype.getItemsCodeList=function(e){var t=e.type,s=null;if(t=="last"){s=this.getLastItems()}else if(t=="search"){s=e.items}else{s=this.getEntityItems(this.entities[t.toUpperCase()])}return s};e.UI.Selector.prototype.buildContentCollection=function(t){var s=t.type,i=[],n=null,a=null,o=null;var r=this.getItemsCodeList(t);var c=e.util.in_array(s,["last","search"]);if(c){var p=[];for(var l in this.dialogGroups){if(this.dialogGroups.hasOwnProperty(l)){n=this.dialogGroups[l];p.push({code:l,value:typeof n.SORT!="undefined"&&parseInt(n.SORT)>0?parseInt(n.SORT):100})}}p.sort((function(e,t){if(e.value<t.value){return-1}if(e.value>t.value){return 1}return 0}));var h={tab:s,group:0};for(o=0;o<p.length;o++){l=p[o].code;a=this.drawItemsGroup({groupCode:l,itemsCodeList:r,descLessMode:e.type.isNotEmptyString(this.dialogGroups[l].DESC_LESS_MODE)&&this.dialogGroups[l].DESC_LESS_MODE=="Y",navData:h});if(a){i.push(a)}}}else if(e.type.isNotEmptyObject(this.entities[s.toUpperCase()])){var d={type:s,itemsCodeList:r,descLessMode:e.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[s.toUpperCase()].additionalData.DESC_LESS_MODE)&&this.entities[s.toUpperCase()].additionalData.DESC_LESS_MODE=="Y"};if(e.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[s.toUpperCase()].additionalData.TYPE)&&this.entities[s.toUpperCase()].additionalData.TYPE=="tree"){var u=this.drawItemsTreeTabNode(d);for(o=0;o<u.length;o++){i.push(u[o])}}else{var m=this.drawItemsTab(d);if(m){i.push(m)}}}var f=false;if(i.length<=0){if(s=="search"){f=true;this.nodes.contentWaiter=e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},html:e.message("MAIN_UI_SELECTOR_STUB_PLEASE_WAIT")});var y=e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxSearch},children:[this.nodes.contentWaiter]});if(this.getOption("useContainer")=="Y"&&this.nodes.input&&!e.type.isNotEmptyString(this.nodes.input.value)){this.nodes.contentWaiter.style.display="none"}i.push(y)}else{i.push(e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxSearch},children:[e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},html:e.message("MAIN_UI_SELECTOR_STUB_EMPTY_LIST")})]}))}}if(typeof this.result[s]!="undefined"){this.cursors[s]={firstItem:!f?this.result[s][0][0][0]:null,currentItem:!f?this.result[s][0][0][0]:null,position:{group:0,row:0,column:0}}}return i};e.UI.Selector.prototype.getLastItems=function(){var t={};for(var s in this.entities){if(this.entities.hasOwnProperty(s)&&e.type.isArray(this.entities[s].itemsLast)){if(typeof t[s]=="undefined"){t[s]=[]}for(var i=0;i<this.entities[s].itemsLast.length;i++){if(e.util.in_array(this.entities[s].itemsLast[i],t[s])){continue}t[s].push(this.entities[s].itemsLast[i])}}}return t};e.UI.Selector.prototype.getEntityItems=function(t){var s=[];if(!e.type.isNotEmptyObject(t)){return s}for(var i in t.items){if(t.items.hasOwnProperty(i)){if(e.util.in_array(i,s)||e.type.isNotEmptyString(t.items[i].selectable)&&t.items[i].selectable=="N"){continue}s.push(i)}}return s};e.UI.Selector.prototype.drawItemsGroup=function(t){var s=null;var i=t.groupCode;var n=t.itemsCodeList;if(!i||!e.type.isNotEmptyObject(this.dialogGroups[i])){return s}var a=[],o,r,c,p=null;if(e.type.isNotEmptyObject(this.dialogGroups[i].TYPE_LIST)){var l=[];for(o in this.dialogGroups[i].TYPE_LIST){if(this.dialogGroups[i].TYPE_LIST.hasOwnProperty(o)){c=this.dialogGroups[i].TYPE_LIST[o];if(e.type.isNotEmptyObject(n[c])){for(r in n[c]){if(n[c].hasOwnProperty(r)){p={entityType:c,itemCode:n[c][r]};if(e.type.isNotEmptyObject(this.sortData[p.itemCode])){p.sort=this.sortData[p.itemCode]}l.push(p)}}}}}l.sort((function(e,t){if(typeof e.sort=="undefined"&&typeof t.sort=="undefined"){return 0}else if(typeof e.sort!="undefined"&&typeof t.sort=="undefined"){return-1}else if(typeof e.sort=="undefined"&&typeof t.sort!="undefined"){return 1}else{if(typeof e.sort.Y!="undefined"&&typeof t.sort.Y=="undefined"){return-1}else if(typeof e.sort.Y=="undefined"&&typeof t.sort.Y!="undefined"){return 1}else if(typeof e.sort.Y!="undefined"&&typeof t.sort.Y!="undefined"){if(parseInt(e.sort.Y)>parseInt(t.sort.Y)){return-1}else if(parseInt(e.sort.Y)<parseInt(t.sort.Y)){return 1}else{return 0}}else{if(parseInt(e.sort.N)>parseInt(t.sort.N)){return-1}else if(parseInt(e.sort.N)<parseInt(t.sort.N)){return 1}else{return 0}}}}));var h=null,d=false,u=0,m=0;for(var f=0;f<l.length;f++){if(f==0){if(typeof this.result[t.navData.tab]=="undefined"){this.result[t.navData.tab]=[]}this.result[t.navData.tab][t.navData.group]=[];d=true}if(m==2){m=0;u++}if(typeof this.result[t.navData.tab][t.navData.group][u]=="undefined"){this.result[t.navData.tab][t.navData.group][u]=[]}h=this.drawItem(l[f]);if(h){this.result[t.navData.tab][t.navData.group][u][m]={entityType:l[f].entityType,itemCode:l[f].itemCode};a.push(h);m++}}if(d){t.navData.group++}}if(a.length>0){s=e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxPrefix+i},children:[e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxName},html:this.dialogGroups[i].TITLE}),e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},children:a})]})}return s};e.UI.Selector.prototype.drawItemsTab=function(t){var s=t.type;var i=t.itemsCodeList;var n=[],a=0,o=0,r=0,c=null;if(e.type.isNotEmptyObject(i)){for(var p in i){if(i.hasOwnProperty(p)){if(a==0){this.result[t.type]=[];this.result[t.type][0]=[]}if(r==2){r=0;o++}if(typeof this.result[t.type][0][o]=="undefined"){this.result[t.type][0][o]=[]}c={entityType:s.toUpperCase(),itemCode:i[p]};this.result[t.type][0][o][r]=c;n.push(this.drawItem(c));r++}a++}}return e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxPrefix+s},children:[e.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},children:n})]})};e.UI.Selector.prototype.drawItemsTreeTabNode=function(t){var s=[];var i=e.type.isNotEmptyString(t.type)?t.type:false,n=t.relation!="undefined"?t.relation:false,a=t.categoryId!="undefined"?t.categoryId:false,o=t.categoryOpened,r=false,c=null,p=null,l=null;if(!n&&e.type.isNotEmptyObject(this.entities[i.toUpperCase()+"_RELATION"])&&e.type.isNotEmptyObject(this.entities[i.toUpperCase()+"_RELATION"].items)){n=this.entities[i.toUpperCase()+"_RELATION"].items;r=true}if(!n){return s}var h=e.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.SELECT_TEXT)?this.entities[i.toUpperCase()].additionalData.SELECT_TEXT:e.message("MAIN_UI_SELECTOR_SELECT_TEXT");var d=e.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.SELECT_FLAT_TEXT)?this.entities[i.toUpperCase()].additionalData.SELECT_FLAT_TEXT:e.message("MAIN_UI_SELECTOR_SELECT_FLAT_TEXT");var u=null,m=null,f=null,y=null;for(c in n){if(n.hasOwnProperty(c)&&n[c].type=="category"){p=this.entities[i.toUpperCase()].items[n[c].id];r=r&&p.id!="EX";u=e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranch+" "+(r?this.getRenderInstance().class.treeBranchOpened:"")},children:[e.create("A",{attrs:{href:"#"+p.id,hidefocus:"true","data-entity-id":p.entityId},props:{className:this.getRenderInstance().class.treeBranchInner},events:{click:function(e){this.openTreeItem({treeItemNode:e.currentTarget.parentNode,entityType:i,categoryId:e.currentTarget.getAttribute("data-entity-id")});e.stopPropagation();return e.preventDefault()}.bind(this)},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchArrow}}),e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchText},html:p.name})]})]});s.push(u);f=e.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.ALLOW_SELECT)&&this.entities[i.toUpperCase()].additionalData.ALLOW_SELECT=="Y"&&!r&&p.id!="EX"?e.create("A",{attrs:{hidefocus:"true",href:"#"+n[c].id,"data-item-id":n[c].id,"data-entity-type":i.toUpperCase()},props:{className:this.getRenderInstance().class.treeBranchCheckBox+" "+(typeof this.itemsSelected[n[c].id]!="undefined"?this.getRenderInstance().class.treeBranchCheckBoxSelected:"")+" "+this.getRenderInstance().class.itemElement},events:{click:function(e){this.selectItem({itemId:e.currentTarget.getAttribute("data-item-id"),entityType:e.currentTarget.getAttribute("data-entity-type"),itemNode:e.currentTarget,className:this.getRenderInstance().class.treeBranchCheckBoxSelected});e.stopPropagation();return e.preventDefault()}.bind(this)},children:[e.create("SPAN",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxInner},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxArrow}}),e.create("DIV",{attrs:{rel:p.name+": "+h},props:{className:this.getRenderInstance().class.treeBranchCheckBoxText},html:h})]})]}):null;y=[f];if(e.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.ALLOW_FLAT)&&this.entities[i.toUpperCase()].additionalData.ALLOW_FLAT=="Y"&&p.id!="EX"&&e.type.isNotEmptyString(this.entities[i.toUpperCase()].items[n[c].id].idFlat)){f=e.create("A",{attrs:{hidefocus:"true",href:"#"+this.entities[i.toUpperCase()].items[n[c].id].idFlat,"data-item-id":this.entities[i.toUpperCase()].items[n[c].id].idFlat,"data-entity-type":i.toUpperCase()},props:{className:this.getRenderInstance().class.treeBranchCheckBox+" "+(typeof this.itemsSelected[n[c].id]!="undefined"?this.getRenderInstance().class.treeBranchCheckBoxSelected:"")+" "+this.getRenderInstance().class.itemElement},events:{click:function(e){this.selectItem({itemId:e.currentTarget.getAttribute("data-item-id"),entityType:e.currentTarget.getAttribute("data-entity-type"),itemNode:e.currentTarget,className:this.getRenderInstance().class.treeBranchCheckBoxSelected});e.stopPropagation();return e.preventDefault()}.bind(this)},children:[e.create("SPAN",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxInner},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxArrow}}),e.create("DIV",{attrs:{rel:p.name+": "+d},props:{className:this.getRenderInstance().class.treeBranchCheckBoxText},html:d})]})]});y.push(f)}var g=e.clone(t);g.relation=n[c].items;g.categoryId=p.entityId;g.categoryOpened=r;var I=this.drawItemsTreeTabNode(g);if(I.length>0){for(l=0;l<I.length;l++){y.push(I[l])}}m=e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchLeavesContainer+" "+(r?this.getRenderInstance().class.treeBranchLeavesContainerOpened:"")},children:y});s.push(m)}}if(a){var b=[],S=null,C=0;for(l in n){if(n.hasOwnProperty(l)&&n[l].type==this.entities[i.toUpperCase()].additionalData.RELATION_ENTITY_TYPE){S=this.entities[n[l].type].items[n[l].id];if(!S){continue}b.push(this.drawTreeLeafItem({entityType:n[l].type,item:S}));C++}}if(C<=0){if(!e.type.isNotEmptyObject(this.treeItemLoaded[i])||!this.treeItemLoaded[i][a]){b.push(e.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchLeavesWaiter},html:e.message("MAIN_UI_SELECTOR_PLEASE_WAIT")}))}if(o){this.getTreeItemRelation({entityType:i,categoryId:a})}}s.push(e.create("DIV",{attrs:{id:"bx-lm-category-relation-"+a},props:{className:this.getRenderInstance().class.treeLeavesList},children:b}))}return s};e.UI.Selector.prototype.drawTreeLeafItem=function(t){var s=t.entityType,i=t.item;var n=typeof this.itemsSelected[i.id]!="undefined"?this.getRenderInstance().class.treeLeafSelected:"";return e.create("A",{attrs:{href:"#"+i.id,rel:i.id,hidefocus:"true","data-item-id":i.id,"data-entity-type":s},props:{className:this.getRenderInstance().class.treeLeaf+" "+n+" "+this.getRenderInstance().class.itemElement},events:{click:function(e){this.selectItem({itemNode:e.currentTarget,itemId:e.currentTarget.getAttribute("data-item-id"),entityType:e.currentTarget.getAttribute("data-entity-type"),className:this.getRenderInstance().class.treeLeafSelected});e.stopPropagation();return e.preventDefault()}.bind(this)},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.treeLeafInfo},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.treeLeafName},html:i.name}),e.create("DIV",{props:{className:this.getRenderInstance().class.treeLeafDescription},html:i.desc})]}),e.create("DIV",{attrs:{style:i.avatar?"background:url('"+encodeURI(i.avatar)+"') no-repeat center center; background-size: cover;":""},props:{className:this.getRenderInstance().class.treeLeafAvatar}})]})};e.UI.Selector.prototype.openTreeItem=function(t){var s=e.type.isDomNode(t.treeItemNode)?t.treeItemNode:null,i=t.categoryId,n=t.entityType;var a=!e.hasClass(s,this.getRenderInstance().class.treeBranchOpened);e.toggleClass(s,this.getRenderInstance().class.treeBranchOpened);var o=e.findNextSibling(s,{tagName:"div"});if(e.hasClass(o,this.getRenderInstance().class.treeBranchLeavesContainer)){e.toggleClass(o,this.getRenderInstance().class.treeBranchLeavesContainerOpened)}if(a){this.getTreeItemRelation({entityType:n,categoryId:i})}return false};e.UI.Selector.prototype.getTreeItemRelation=function(t){var s=t.categoryId;if(!e.type.isUndefined(this.treeItemLoaded[s])){return false}t.callback=this.getTreeItemRelationCallback.bind(this);t.entityType=t.entityType.toUpperCase();t.selectorId=this.id;t.allowSearchSelf=e.type.isNotEmptyObject(this.entities["USERS"])&&this.entities["USERS"].options.allowSearchSelf;e.onCustomEvent(this,"BX.UI.SelectorManager:getTreeItemRelation",[t])};e.UI.Selector.prototype.getTreeItemRelationCallback=function(t){if(typeof t.selectorInstanceId=="undefined"||this.id!=t.selectorInstanceId){return}var s=t.entityType,i=t.categoryId,n=t.data,a={},o=null;if(i!="EX"){i=parseInt(i)}if(typeof this.treeItemLoaded[s]=="undefined"){this.treeItemLoaded[s]={}}this.treeItemLoaded[s][i]=true;var r=e.util.object_search_key(i=="EX"?i:this.entities[s.toUpperCase()].additionalData.PREFIX+i,this.entities[s.toUpperCase()+"_RELATION"].items);if(e.type.isNotEmptyObject(this.entities[s.toUpperCase()])&&e.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&e.type.isNotEmptyString(this.entities[s.toUpperCase()].additionalData.RELATION_ENTITY_TYPE)){o=this.entities[s.toUpperCase()].additionalData.RELATION_ENTITY_TYPE;a=n[o]}var c=null;if(e.type.isNotEmptyObject(r.items)){for(c in r.items){if(!r.items.hasOwnProperty(c)){continue}if(r.items[c].type==o){delete r.items[c]}}}e.cleanNode(e("bx-lm-category-relation-"+i));for(c in a){if(a.hasOwnProperty(c)&&e.type.isNotEmptyObject(this.entities[o])){if(!e.type.isNotEmptyObject(this.entities[o].items[c])){this.entities[o].items[c]=a[c]}if(e("bx-lm-category-relation-"+i)&&!r.items[c]){r.items[c]={id:c,type:o};e("bx-lm-category-relation-"+i).appendChild(this.drawTreeLeafItem({entityType:o,item:this.entities[o].items[c]}))}}}if(this.popups.container){this.popups.container.adjustPosition()}if(this.popups.main){this.popups.main.adjustPosition()}};e.UI.Selector.prototype.drawItem=function(t){var s=null;var i=e.type.isNotEmptyString(t.entityType)?t.entityType:null;var n=e.type.isNotEmptyString(t.itemCode)?t.itemCode:null;if(!i||!n){return s}var a=e.type.isNotEmptyObject(this.entities[i])&&e.type.isNotEmptyObject(this.entities[i].items)&&e.type.isNotEmptyObject(this.entities[i].items[n])?this.entities[i].items[n]:null;if(!a){return s}var o=a.name,r=e.type.isNotEmptyString(a.desc)?a.desc:"";if(this.getOption("emailDescMode")!="Y"&&e.type.isNotEmptyString(a.showEmail)&&a.showEmail=="Y"&&e.type.isNotEmptyString(a.email)){o+=" ("+a.email+")"}var c=e.type.isNotEmptyString(a.desc);c=t.descLessMode&&t.descLessMode==true?false:c;c=c||a.showDesc;var p=typeof t.emailDescMode!="undefined"&&t.emailDescMode==true;if(p===true){c=true}var l=null;if(e.type.isNotEmptyString(a.avatar)){l=e.create("DIV",{props:{className:this.getRenderInstance().class.itemAvatar},children:[e.create("IMG",{attrs:{src:encodeURI(a.avatar),"bx-lm-item-id":a.id,"bx-lm-item-type":i.toLowerCase()},props:{className:this.getRenderInstance().class.itemAvatarImage},events:{error:function(){e.onCustomEvent("removeClientDbObject",[e.UI.SelectorManager,this.getAttribute("bx-lm-item-id"),this.getAttribute("bx-lm-item-type")]);e.cleanNode(this,true)}}}),e.create("SPAN",{props:{className:this.getRenderInstance().class.itemAvatarStatus}})]})}else{l=e.create("DIV",{props:{className:this.getRenderInstance().class.itemAvatar+" "+(a.iconCustom?this.getRenderInstance().class.itemAvatarCustom:"")},html:a.iconCustom?a.iconCustom:""})}return e.create("A",{attrs:{id:this.getItemNodeId({entityType:i,itemId:a.id}),hidefocus:"true",rel:a.id,"data-entity-type":i},props:{className:this.getRenderInstance().class.item+" "+this.getRenderInstance().class.itemElement+" "+(typeof this.itemsSelected[a.id]!="undefined"?this.getRenderInstance().class.itemSelected:"")+" "+(t.itemHover?this.getRenderInstance().class.itemHover:"")+" "+(c?this.getRenderInstance().class.itemShowDescriptionMode:"")+" "+(t.className?" "+t.className:"")+" "+this.getRenderInstance().class.itemElementTypePrefix+i.toLowerCase()+" "+(this.getOption("avatarLessMode")=="Y"?this.getRenderInstance().class.itemAvatarlessMode:"")+" "+(e.type.isNotEmptyString(a.isExtranet)&&a.isExtranet=="Y"||e.type.isNotEmptyString(a.isNetwork)&&a.isNetwork=="Y"?this.getRenderInstance().class.itemElementExtranet:"")+" "+(e.type.isNotEmptyString(a.isCrmEmail)&&a.isCrmEmail=="Y"?this.getRenderInstance().class.itemElementCrmEmail:"")+" "+(e.type.isNotEmptyString(a.isEmail)&&a.isEmail=="Y"?this.getRenderInstance().class.itemElementEmail:"")+" "+(i.toLowerCase()=="users"&&this.getOption("showVacations")=="Y"&&e.type.isNotEmptyObject(this.entities[i].additionalData)&&e.type.isNotEmptyObject(this.entities[i].additionalData["USERS_VACATION"])&&e.type.isNotEmptyString(this.entities[i].additionalData["USERS_VACATION"][a.entityId])?this.getRenderInstance().class.itemElementVacation:"")},events:{click:function(e){this.selectItem({entityType:e.currentTarget.getAttribute("data-entity-type"),itemNode:e.currentTarget,itemId:a.id});e.stopPropagation();return e.preventDefault()}.bind(this)},children:[l,e.create("DIV",{props:{className:this.getRenderInstance().class.itemSpace}}),e.create("DIV",{props:{className:this.getRenderInstance().class.itemInfo},children:[e.create("DIV",{props:{className:this.getRenderInstance().class.itemName},html:o}),c?e.create("DIV",{props:{className:this.getRenderInstance().class.itemDescription},html:r}):null]})]})};e.UI.Selector.prototype.isDialogOpen=function(){return this.popups.main!=null||this.popups.container!=null};e.UI.Selector.prototype.isContainerOpen=function(){return this.popups.container!=null};e.UI.Selector.prototype.isSearchOpen=function(){return this.popups.search!=null||this.popups.container!=null};e.UI.Selector.prototype.closeDialog=function(t){var s=e.type.isNotEmptyObject(t)&&!!t.silent;if(this.popups.main!=null){if(s){this.popups.main.destroy()}else{this.popups.main.close()}}else if(this.popups.container!=null){if(s){this.popups.container.destroy()}else{this.popups.container.close()}}e.onCustomEvent("BX.UI.SelectorManager:onDialogClose",[this]);return true};e.UI.Selector.prototype.closeSearch=function(){if(this.popups.search){this.popups.search.close()}else if(this.popups.container){this.popups.container.close()}this.closeByEmptySearchResult=false;return true};e.UI.Selector.prototype.closeAllPopups=function(){for(var e in this.popups){if(!this.popups.hasOwnProperty(e)){continue}if(this.popups[e]){this.popups[e].close()}}};e.UI.Selector.prototype.getItemNodeId=function(e){return(this.id+"_"+(this.tabs.selected?this.tabs.selected:"")+"_"+e.entityType+"_"+e.itemId).toLowerCase()};e.UI.Selector.prototype.getAdditionalEntitiesData=function(){var t={};for(var s in this.entities){if(!this.entities.hasOwnProperty(s)){continue}t[s]={};if(e.type.isNotEmptyObject(this.entities[s].additionalData)){t[s]=this.entities[s].additionalData}}return t};e.UI.Selector.prototype.setTagTitle=function(){if(e.type.isDomNode(this.nodes.tag)){if(Object.keys(this.itemsSelected).length<=0&&this.getOption("tagLink1")){this.nodes.tag.innerHTML=this.getOption("tagLink1")}else if(Object.keys(this.itemsSelected).length>0&&this.getOption("tagLink2")){this.nodes.tag.innerHTML=this.getOption("tagLink2")}}};e.UI.Selector.prototype.selectItem=function(t){var s=t.itemId,i=t.entityType,n=t.itemNode,a=e.type.isNotEmptyString(t.className)?t.className:this.getRenderInstance().class.itemSelected,o=e.type.isNotEmptyString(t.tab)?t.tab:"";if(!e.type.isNotEmptyString(s)){return false}var r=false;var c=null;if(typeof this.callbackBefore.select=="function"){if(e.type.isNotEmptyObject(this.callbackBefore.context)){c=this.callbackBefore.select.bind(this.callbackBefore.context)(s);r=c&&(Object.prototype.toString.call(c)==="[object Promise]"||c.toString()==="[object BX.Promise]")}}if(!r){c=Promise.resolve()}c.then(function(e){this.selectItemPromiseFulfilled({itemId:s,entityType:i,itemNode:n,className:a,tab:o})}.bind(this),function(e){this.selectItemPromiseRejected({itemId:s,entityType:i,itemNode:n,className:a,tab:o})}.bind(this))};e.UI.Selector.prototype.selectItemPromiseFulfilled=function(t){var s=t.itemId,i=t.entityType,n=t.itemNode,a=t.className,o=t.tab;if(this.getOption("focusInputOnSelectItem")!="N"){e.focus(this.input)}if(typeof this.itemsSelected[s]!="undefined"){return this.unselectItem({itemNode:n,itemId:s,entityType:i,className:a})}else{if(this.getOption("multiple")!="Y"){this.itemsSelected={}}this.itemsSelected[s]=i.toLowerCase()}if(!e.type.isArray(this.entities[i].itemsLast)){this.entities[i].itemsLast=[]}if(!e.util.in_array(s,this.entities[i].itemsLast)){this.entities[i].itemsLast.push(s)}e.addClass(n,a);e.onCustomEvent("BX.UI.Selector:onSelectItem",[{selectorId:this.id,itemId:s}]);e.onCustomEvent("BX.UI.Selector:onChange",[{selectorId:this.id}]);if(this.callback.select){this.callback.select({item:this.entities[i].items[s],entityType:i,selectorId:this.id,state:"select",tab:o})}if(this.popups.search){this.popups.search.close()}if(this.getOption("multiple")!="Y"&&this.getOption("preventCloseAfterSelect")!="Y"){if(this.popups.container){this.popups.container.close()}if(this.popups.main){this.popups.main.close()}}this.getSearchInstance().abortSearchRequest()};e.UI.Selector.prototype.selectItemPromiseRejected=function(e){};e.UI.Selector.prototype.deleteSelectedItem=function(t){var s=t.itemId;if(!e.type.isNotEmptyString(s)){return false}if(this.popups.main){var i=e.findChildren(this.popups.main.popupContainer,{attrs:{rel:s}},true);if(i){for(var n=0;n<i.length;n++){e.removeClass(i[n],this.getRenderInstance().class.itemSelected);e.removeClass(i[n],this.getRenderInstance().class.treeLeafSelected)}}}e.onCustomEvent("BX.UI.Selector:onChange",[{selectorId:this.id}]);delete this.itemsSelected[s]};e.UI.Selector.prototype.unselectItem=function(t){var s=t.itemId,i=t.entityType,n=t.itemNode,a=e.type.isNotEmptyString(t.className)?t.className:this.getRenderInstance().class.itemSelected;if(!e.type.isNotEmptyString(s)){return false}if((!e.type.isNotEmptyString(t.mode)||t.mode!="reinit")&&(typeof this.itemsSelected[s]=="undefined"||e.util.in_array(s,this.itemsUndeletable))){return false}else{delete this.itemsSelected[s]}e.removeClass(n,a);if(this.callback.unSelect){this.callback.unSelect({item:this.entities[i].items[s],entityType:i,selectorId:this.id})}if(this.getOption("multiple")!="Y"&&this.getOption("preventCloseAfterSelect")!="Y"){if(this.popups.container){this.popups.container.close()}if(this.popups.main){this.popups.main.close()}if(this.popups.search){this.popups.search.close()}}return false};e.UI.Selector.prototype.deleteLastItem=function(){var t=false;for(var s in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(s)){t=s}}if(t&&!e.util.in_array(t,this.itemsUndeletable)){var i=this.itemsSelected[t];delete this.itemsSelected[t];if(this.callback.unSelect){this.callback.unSelect({item:this.entities[i.toUpperCase()].items[t],entityType:i.toUpperCase(),selectorId:this.id})}}};e.UI.Selector.prototype.reinit=function(){var t=null;if(this.callback.select){for(var s in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(s)){t=this.itemsSelected[s];if(e.type.isNotEmptyObject(this.entities[t.toUpperCase()])&&e.type.isNotEmptyObject(this.entities[t.toUpperCase()].items)&&e.type.isNotEmptyObject(this.entities[t.toUpperCase()].items[s])){this.callback.select({item:this.entities[t.toUpperCase()].items[s],entityType:t,selectorId:this.id,state:"init"})}}}}};e.UI.Selector.prototype.getItemsSelectedSorted=function(){var t=[],s=null;for(var i in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(i)){s=this.itemsSelected[i];t.push({itemId:i,entityType:s,sort:e.type.isNotEmptyObject(this.entities)&&e.type.isNotEmptyObject(this.entities[s.toUpperCase()])&&e.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&typeof this.entities[s.toUpperCase()].additionalData.SORT_SELECTED!="undefined"?parseInt(this.entities[s.toUpperCase()].additionalData.SORT_SELECTED):100})}}t.sort((function(e,t){if(e.sort<t.sort){return-1}if(e.sort>t.sort){return 1}return 0}));return t}})();
//# sourceMappingURL=selector.map.js